package com.fick.util;

import java.text.SimpleDateFormat;
import java.util.Date;

import com.fick.hibernate.dao.VisitInfoDAO;

public class OnlineCount {

	public static void main(String args[]) {
		// System.out.print(new OnlineCount().getTodayNews());
	}

	// 获取总的该问量
	public int all() {
		String sql = "select count(*) from VisitInfo";
		return (Integer) new VisitInfoDAO().getSession().createQuery(sql).uniqueResult();
	}

	// 获得总信息量
	public int getAllNews() {
		String sql = "select count(*) from News";
		return (Integer) new VisitInfoDAO().getSession().createQuery(sql).uniqueResult();
	}

	public int getTodayNews() {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-M-d hh:mm:ss");
		String date = sdf.format(new Date());
		System.out.print(date);
		String sql = "select count(*) from News where  addDate >GetDate()-1 ";
		return (Integer) new VisitInfoDAO().getSession().createQuery(sql).uniqueResult();

	}

	// 获取今日该问量
	public int toDay() {
		String sql = "select count(*) from VisitInfo where (DATEDIFF(dd,addtime,getdate())=0)";
		return (Integer) new VisitInfoDAO().getSession().createQuery(sql).uniqueResult();
	}

}
